package cn.lyf.entity;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Document("t_user")
public class User implements UserDetails {

    @Id
    private String id;
    @Indexed
    private String username;//用户名
    private String password;//密码
    private String nickname;//网名
    private String role;//用户角色

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
<<<<<<< HEAD
        List<SimpleGrantedAuthority> lst = new ArrayList<>();
            String arr[] =this.role.split(",");
            for (String s:arr){
                SimpleGrantedAuthority sga = new SimpleGrantedAuthority(s.trim());
                System.out.println(s);
                lst.add(sga);
            }
=======
        String arr[] =this.role.split(",");
        List<SimpleGrantedAuthority> lst = new ArrayList<>();
        for (String s:arr){
            SimpleGrantedAuthority sga = new SimpleGrantedAuthority(s.trim());
            System.out.println(s);
            lst.add(sga);
        }
>>>>>>> a254f66694e58548627c0548f6e222a03570bbfd
        return lst;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    @Override
    public String toString() {
        return "User{" +
                "id='" + id + '\'' +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", nickname='" + nickname + '\'' +
                ", role='" + role + '\'' +
                '}';
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
